<template>
    <div class="container">
        <div class="userinfo">
            <img bindtap="bindViewTap" class="userinfo-avatar" :src="userInfo.headimgurl"  v-if="userInfo.headimgurl">
            <div class="iconfont icon-head2 userinfo-avatar" v-else @click="login"></div>
            <span class="userinfo-nickname">{{userInfo.nickname}}</span>
        </div>
        <div class="eventlist">
            <div class="row" @click="addresslist">
                <div class="iconfont icon-address "></div>
                <span>地址管理</span>
            </div>
            <div class="row" @click="record">
                <div class="signin-icon event-icon"></div>
                <span>我的秒杀</span>
            </div>
        </div>
    </div>
</template>

<script>
    import { Toast } from 'mint-ui';

    export default {
        name: "MyCenter",
        components: {},
        data() {
            return {

            }
        },
        computed:{
            userInfo() {
                if(this.$store.getters.getToken)
                    return this.$store.getters.getUserInfo
                else return {
                    nickname: '点击头像登陆',
                    headimgurl:''
                }
            },
        },
        methods: {
            getUserToken() {
                return this.$store.getters.getToken
            },
            getUserInfo() {
                return this.$store.getters.getUserInfo
            },
            checkuserlogin( path ) {
                let token = this.getUserToken()
                if (token !== null && token !== '') {
                    this.$router.push( path )
                } else {
                    Toast( {
                        message: '请先登录',
                        position: 'middle',
                        duration: 1000
                    } );
                }
            },
            addresslist() {
                this.checkuserlogin( "/addresslist" )
            },
            record() {
                this.checkuserlogin( "/myOrders" )
            },
            login() {
                if (!this.getUserToken()) {
                    this.$emit( 'login' )
                }
            }
        }
    }
</script>

<style scoped>
    .container {
        height: 100vh;
    }
    .userinfo {
        padding: 50px 0 30px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        flex-wrap: wrap;
        background-repeat: no-repeat; /** 不重复*/
        background-size: cover;
        background-image: url("../../../static/images/mypoint_bg.png");

    }

    .userinfo-avatar {
        width: 130px;
        height: 130px;
        border-radius: 50%;
        border: 5px solid #ffa485;
        margin: 0 auto;

    }

    .userinfo-avatar.iconfont{
        font-size: 130px;
        color: #fff;
        opacity: 0.8;
        border: 0;
    }
    .userinfo-nickname {
        color: #fff;
        margin: 10px auto;
    }

    .userinfo-totalpoint {
        margin: 10px auto 0;
    }

    .icon-address {
        font-size: 40px;
        margin-right: 10px;
        color: #f8c961
    }

    .userinfo-totalpoint .point-icon {
        width: 58px;
        height: 58px;
        margin-top: 2px;
        margin-left: -22px;
    }

    .userinfo-totalpoint .point-num {
        font-size: 60px;
        font-weight: 800;
        color: #ffe349;
        line-height: 60px;
        margin-left: 10px;
    }

    .userinfo-totalpoint .point-jifen {
        font-size: 28px;
        font-weight: 800;
        color: #ffe349;
        line-height: 28px;
        margin-top: 25px;
        margin-left: 8px;
    }


    .signin-item img {
        width: 25px;
        height: 25px;
    }

    .signin-item span {
        margin-top: 5px;
    }

    .eventlist {
        margin-top: 18px;
        display: flex;
        flex-direction: column;
    }

    .eventlist .row {
        display: flex;
        flex-direction: row;
        position: relative;
        padding: 16px 0;
        margin: 0 24px;
        height: 96px;
        line-height: 64px;
        border-bottom: 1px solid rgba(229, 229, 229, 1);
    }

    .eventlist .row a {

    }

    .eventlist .row .event-icon {
        margin-top: 10px;
        width: 36px;
        height: 36px;
        margin-right: 15px;
    }

    .eventlist .row .todaypoints {
        color: #fc5a5a;
        font-size: 26px;
        font-weight: 800;
        width: 100px;
        span-align: center;
        right: 20px;
        position: absolute;
    }

    .eventlist .event-title {
        font-size: 26px;
        font-weight: 600;
    }

    .eventlist .event-info {
        color: rgba(119, 119, 119, 1);
        font-size: 20px;
        margin-left: 20px;
        margin-top: 3px;
    }

    .eventlist .row-btn {
        display: inline-block;
        margin-top: 7px;
        width: 100px;
        height: 48px;
        line-height: 48px;
        span-align: center;
        font-size: 22px;
        padding: 0;
        border-radius: 5px;
        right: 20px;
        border: 1px solid #353535;
        position: absolute;
    }

    .eventlist .row-btn.hassigned {
        color: rgba(53, 53, 53, 0.6);
        border-color: rgba(53, 53, 53, 0.6);
        background-color: transparent;
    }
</style>
